//
//  StartCell.m
//  AnnCar_user
//
//  Created by LiBenCan on 17/10/24.
//  Copyright © 2017年 LiBenCan. All rights reserved.
//

#import "StartCell.h"

@implementation StartCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        self.selectionStyle = 0;
    }
    return self;
}

//创建星星View
- (void)loadCell:(NSString *)titleStr SecondStr:(NSString *)startStr
{
    if (!_titleLab) {
        //标题
        _titleLab = [UILabel new];
        [self.contentView addSubview:_titleLab];
        _titleLab.text = titleStr;
        _titleLab.font = [UIFont systemFontOfSize:15*screenW_6];
        _titleLab.textColor = TextBlack;
        [_titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(20 * screenW_6);
            make.top.equalTo(self.contentView).offset(0);
            make.height.equalTo(@(49*screenW_6));
            make.width.equalTo(@(80*screenW_6));
        }];
        
        //星星View
        _startView = [UIView new];
        [self.contentView addSubview:_startView];
        [_startView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.titleLab.mas_right).offset(0);
            make.top.equalTo(self.contentView).offset(0);
            make.height.equalTo(@(49*screenW_6));
            make.width.equalTo(@(SCREENW-120*screenW_6));
        }];
        [self CreatStart:[startStr integerValue]];
        
        //画线
        _lineLab = [UILabel new];
        [self.contentView addSubview:_lineLab];
        _lineLab.backgroundColor = LineColor;
        [_lineLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.height.equalTo(@1);
            make.left.equalTo(@(15*screenW_6));
            make.right.equalTo(@0);
            make.top.equalTo(self.startView.mas_bottom).offset(0*screenW_6);
            make.bottom.equalTo(self.contentView.mas_bottom).offset(0);
        }];


    }
}

//创建View
-(void)CreatStart:(NSInteger)startNumber
{
    //移除星星
    for (UIImageView *imageSubView in _startView.subviews) {
        [imageSubView removeFromSuperview];
    }
    
    //循环创建
    for (int i = 0; i< 5; i++) {
        UIImageView *starImageV = [[UIImageView alloc]initWithFrame:CGRectMake(30*screenW_6*i,15*screenW_6, 20*screenW_6, 20*screenW_6)];
        [_startView addSubview:starImageV];
        starImageV.tag = i;
        starImageV.userInteractionEnabled = YES;
        if (i < startNumber) {//创建实体星星
            starImageV.image = [UIImage imageNamed:@"Order_start1"];
        }else
        {
            starImageV.image = [UIImage imageNamed:@"Order_satrt2"];
        }
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(startTap:)];
        [starImageV addGestureRecognizer:tap];
    }
    
}
//星星点击事件
-(void)startTap:(UITapGestureRecognizer *)tap
{
    [self CreatStart:tap.view.tag+1];
    if (_startBlock) {
        self.startBlock(tap.view.tag);
    }
}
@end
